1 /**
2  * License:
3  *              Copyright Devisualization (Richard Andrew Cattermole) 2014 - 2017.
4  *     Distributed under the Boost Software License, Version 1.0.
5  *        (See accompanying file LICENSE_1_0.txt or copy at
6  *              http://www.boost.org/LICENSE_1_0.txt)
7  */
8 module devisualization.util.core.math;
9 
10 private {
11 	static const(ulong[]) factorialLookupTable = [
12 		1,
13 		1,
14 		2,
15 		6,
16 		24,
17 		120,
18 		720,
19 		5040,
20 		40320,
21 		362880,
22 		3628800,
23 		39916800,
24 		479001600,
25 		6227020800,
26 		87178291200,
27 		1307674368000,
28 		20922789888000,
29 		355687428096000,
30 		6402373705728000,
31 		121645100408832000,
32 		2432902008176640000
33 	];
34 }
35 
36 /**
37  * Returns a cached factorial value.
38  * 
39  * Params:
40  * 		n	=	How many times to recurse
41  * 
42  * Returns:
43  * 		A cached value of factorial between 0 and 32 recursion.
44  */
45 double factorial(size_t n) @safe nothrow
46 in {
47 	assert(n >= 0);
48 	assert(n < factorialLookupTable.length);
49 } body {
50 	return factorialLookupTable[n];
51 }